﻿Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Diagnostics

Partial Public Class frmWinTaskDemo
    Public Sub New()
        InitializeComponent()
    End Sub
    'DisplayStartupMenu
    'DisplayRunDialog
    'DisplayLogoffDialog
    'ArrangeCascade
    'ArrangeTileHrz
    'ArrangeTileVrt
    'ShowDesktop
    'ShowDateTimeDialog
    'ShowTaskbarPrps
    'MinAll
    'MaxAll
    'ShowDesktop2
    'ShowTaskMngr
    'TaskBrCustomizeNtfy
    'LockTaskbar
    'HelpAndSuppCenter
    'ControlPanel
    'TurnOffCompDialog
    'PrintersAndFaxesDialog
    'FindFilesDialog
    'FindComputers
    Private nEventIds As Integer() = {305, 401, 402, 403, 404, 405, _
     407, 408, 413, 415, 416, 419, _
     420, 421, 424, 503, 505, 506, _
     510, 41093, 41094}

    Private Sub frmWinTaskDemo_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        cboTasks.Items.Add("Start menu")
        cboTasks.Items.Add("Run dialog")
        cboTasks.Items.Add("Log off dialog")
        cboTasks.Items.Add("Cascade windows")
        cboTasks.Items.Add("Tile windows horizontally")
        cboTasks.Items.Add("Tile windows vertically")
        cboTasks.Items.Add("Show desktop")
        cboTasks.Items.Add("Date time dialog")
        cboTasks.Items.Add("Task bar properties")
        cboTasks.Items.Add("Minimize all")
        cboTasks.Items.Add("Maximize all")
        cboTasks.Items.Add("Show desktop 2")
        cboTasks.Items.Add("Show task manager")
        cboTasks.Items.Add("Task bar customize notifications")
        cboTasks.Items.Add("Lock taskbar")
        cboTasks.Items.Add("Help and support center")
        cboTasks.Items.Add("Control panel")
        cboTasks.Items.Add("Turn off computer dialog")
        cboTasks.Items.Add("Printers and faxes dialog")
        cboTasks.Items.Add("Find files dialog")
        cboTasks.Items.Add("Find computers")

    End Sub

    Private Sub cboTasks_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cboTasks.SelectedIndexChanged
        Dim iHandle As Integer
        Dim selIndex As Integer = cboTasks.SelectedIndex

        iHandle = MyWin32.FindWindow("Shell_TrayWnd", String.Empty)
        MyWin32.SendMessage(iHandle, MyWin32.WM_COMMAND, MyWin32.MakeLong(nEventIds(selIndex), 0), 0)


    End Sub
End Class

    Public Class MyWin32

        ' The WM_COMMAND message is sent when the user
        ' selects a command item from a menu, 
        ' when a control sends a notification message
        Public Const WM_COMMAND As Integer = &H111

        ' class name 
        <DllImport("user32.dll")> _
        Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
        End Function
        ' window name 

        ' handle to destination window 
        ' message 
        ' first message parameter 
        <DllImport("user32.dll")> _
        Public Shared Function SendMessage(ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
        ' second message parameter 

        Public Shared Function MakeLong(ByVal LoWord As Integer, ByVal HiWord As Integer) As Integer
            Return (HiWord << 16) Or (LoWord And &HFFFF)
        End Function
    End Class
